package cn.tedu.hotel.service.impl;

import cn.tedu.hotel.ex.ServiceException;
import cn.tedu.hotel.mapper.PriceMapper;
import cn.tedu.hotel.pojo.dto.PriceAddNewDTO;
import cn.tedu.hotel.pojo.vo.PriceListItemVO;
import cn.tedu.hotel.pojo.vo.PriceStandardVO;
import cn.tedu.hotel.service.IPriceService;
import cn.tedu.hotel.web.ServiceCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  处理房间价格业务的实现类
 */
@Slf4j
@Service
public class PriceServiceImpl implements IPriceService, ServiceCode {

    @Autowired
    PriceMapper priceMapper;

    public PriceServiceImpl(){
        log.debug("创建业务对象：PriceServiceImpl");
    }

    @Override
    public void addNew(PriceAddNewDTO priceAddNewDTO) {
        log.debug("开始处理【添加房间价格】的业务，参数：{}",priceAddNewDTO);
        //

    }

    @Override
    public void deleteById(Long id) {
        log.debug("开始处理【删除id={}房间价格】的业务",id);
        // 检查房间价格是否存在
        PriceStandardVO queryResult = priceMapper.getStandardById(id);
        log.debug("房间价格的详细信息：queryResult:{}",queryResult);
        if (queryResult == null){
            String message = "删除失败，访问的数据不存在";
            log.debug(message);
            throw new ServiceException(ERR_NOT_FOUND,message);
        }

        //执行删除
        int rows = priceMapper.deleteById(id);
        if (rows != 1){
            String message = "删除失败，服务器繁忙，请稍后再试";
            log.debug(message);
            throw new ServiceException(ERR_DELETE,message);
        }

    }

    @Override
    public List<PriceListItemVO> listPrice() {
        return priceMapper.listPrice();
    }
}
